package com.app.studyroom.mapper;

import java.util.HashMap;
import java.util.Map;

public class ApprovalStatusMapper {

    private static final Map<String, String> codeToName = new HashMap<>();
    private static final Map<String, String> nameToCode = new HashMap<>();

    static {
        // 默认静态映射
        codeToName.put("0", "无审批");
        codeToName.put("1", "待审批");
        codeToName.put("2", "已审批");
        codeToName.put("3", "审批驳回");
        codeToName.put("4", "学习中");
        codeToName.put("5", "学习结束");

        for (Map.Entry<String, String> entry : codeToName.entrySet()) {
            nameToCode.put(entry.getValue(), entry.getKey());
        }
    }

    // ✅ 动态更新接口
    public static void updateMappingFromApi(Map<String, String> data) {
        codeToName.clear();
        nameToCode.clear();
        for (Map.Entry<String, String> entry : data.entrySet()) {
            codeToName.put(entry.getKey(), entry.getValue());
            nameToCode.put(entry.getValue(), entry.getKey());
        }
    }

    public static String getNameByCode(String code) {
        return codeToName.getOrDefault(code, "未知状态");
    }

    public static String getCodeByName(String name) {
        return nameToCode.getOrDefault(name, "-1");
    }
}
